﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

using Gift.DAL;
using Gift.Model;

namespace WebSite.admin.company
{
    public partial class OutInDetail : BaseAdmin
    {
        readonly dalCompany theCompany = new dalCompany();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.BindGrid();
                try
                {
                    string sMoney = theCompany.GetCompanyMoney(Request.QueryString["id"]).ToString();
                    this.lblMoney.Text = string.Format("公司余额:{0}元,人民币大写:{1}", sMoney, Gift.Utile.MathLibrary.CmycurD(decimal.Parse(sMoney)));
                }
                catch (Exception ex)
                {
                    LogFile.Write(ELogType.Error, ex.Message);
                }
            }
        }

  

        string GetSqlWhere
        {
            get
            {
                if (!string.IsNullOrEmpty(Request.QueryString["id"]))
                {
                    string sWhere = string.Empty;

                    if (!string.IsNullOrEmpty(this.dpkTimeFrom.Text.Trim()))
                    {
                        sWhere = string.Format(" and OperateTime >= convert(datetime,'{0}')", this.dpkTimeFrom.Text);
                    }

                    if (!string.IsNullOrEmpty(this.dpkTimeTo.Text.Trim()))
                    {
                        sWhere = sWhere + string.Format(" and convert(datetime,convert(varchar(10),OperateTime,121)) <= convert(datetime, '{0}')", this.dpkTimeTo.Text);
                    }
                    return sWhere;
                }
                else
                {
                    return "";
                }
            }
        }

     




        protected void Grid1_Sort(object sender, ExtAspNet.GridSortEventArgs e)
        {
            DataTable table = theCompany.GetInOutList(Request.QueryString["id"], GetSqlWhere, this.rblInOutType.SelectedItem.Value).Tables[0];
            DataView view1 = table.DefaultView;
            view1.Sort = String.Format("{0} {1}", e.SortField, e.SortDirection);
            Grid1.DataSource = view1;
            Grid1.DataBind();
        }

        private void BindGrid()
        {

            DataTable table = theCompany.GetInOutList(Request.QueryString["id"], GetSqlWhere, this.rblInOutType.SelectedItem.Value).Tables[0];
            Grid1.DataSource = table;
            Grid1.DataBind();

        }



        protected void btnSearch_Click(object sender, EventArgs e)
        {
            this.BindGrid();
        }

        protected void Grid1_PageIndexChange(object sender, ExtAspNet.GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;

        }

    }
}